class MaxSortedDistance{
  getMaxSortedDistance(ary) {
    let max = ary[0]
    let min = ary[0]
    for(let i = 1; i < ary.length; i++) {
      if(ary[i] > max) {
        max = ary[i]
      }
      if(ary[i] < min) {
        min = ary[i]
      }
    }
    let d = max - min
    return d
    // if(d == 0) {
    //   return 0
    // }
    // let bucketNum = ary.length
    // let buckets = new Bucket[bucketNum]
    // for(let i = 0; i < bucketNum; i++) {
    //   buckets[i] = new Bucket()
    // }
    // for(let i=0; i<ary.length; i++) {
    //   let index = ((ary[i] - min) * (bucketNum - 1) / d)
    //   if(buckets[index].min == null || buckets[index.min > ary[i]]) {
    //     buckets[index].min = ary[i]
    //   }
    //   if(buckets[index].max == null || buckets[index].max < ary[i]) {
    //     buckets[index].max = ary[i]
    //   }
    // }

    // let leftMax = buckets[0].max
    // let maxDistance = 0
    // for(let i=1; i<buckets.length; i++) {
    //   if(buckets[i].min == null) {
    //     continue
    //   }
    //   if(buckets[i].min -leftMax > maxDistance) {
    //     maxDistance = buckets[i].min - leftMax
    //   }
    //   leftMax = buckets[i].max
    // }
    // return maxDistance
  }
}

let array = [2,6,3,4,5,10,9]
let distance = new MaxSortedDistance()
console.log(distance.getMaxSortedDistance(array))